#include "TIM_BaseINT.h"                  // Device header

void TIM_BASEINT_Init(){
	  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
	  TIM_InternalClockConfig(TIM2);
	  TIM_TimeBaseInitTypeDef TIM_InitStruct;
	  TIM_TimeBaseStructInit(&TIM_InitStruct);
	  TIM_InitStruct.TIM_Period = 1000-1; // 1khz
	  TIM_InitStruct.TIM_Prescaler = 8400-1; // 1Mhz
	  TIM_TimeBaseInit(TIM2,&TIM_InitStruct);
#define BASE_INTS
#ifdef BASE_INTS
	  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
	  TIM_ClearFlag(TIM2,TIM_IT_Update); // Remove flags

	  NVIC_InitTypeDef NVIC_InitStruct;
	  NVIC_InitStruct.NVIC_IRQChannel= TIM2_IRQn;
	  NVIC_InitStruct.NVIC_IRQChannelCmd= ENABLE;
	  NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority= 0;
	  NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
	  NVIC_Init(&NVIC_InitStruct);
#endif
}


